package com.delaphone.flocash.web.action;

import com.delaphone.flocash.model.FBillServices;
import com.delaphone.flocash.service.PaymentService;
import com.delaphone.flocash.web.util.Validate;
import java.util.List;

/**
 *
 * @author dongtv
 */
public class EnrollPaymentAction extends BaseAction {

    private PaymentService payment;
    private List<FBillServices> allServices;
    private Integer biller;
    private String accName;
    private String accNo;
    private String address;

    @Override
    public String execute() {
        payment.enrollUserService(user.getId(), biller, accNo, accName, 1);
        return SUCCESS;
    }

    @Override
    public void validate() {
        if (biller == -1) {
            addFieldError("biller", getText("user.add_bill.biller.required"));
        }
        if (Validate.isEmptyString(accNo)) {
            addFieldError("accNo", getText("user.add_bill.biller.required"));
        }
        if (Validate.isEmptyString(accName)) {
            addFieldError("accName", getText("user.add_bill.accname.required"));
        }

        if (Validate.isEmptyString(address)) {
            addFieldError("address", getText("user.add_bill.address.required"));
        }
        if (!getFieldErrors().isEmpty()) {
            allServices = payment.getAllBillServices();
        }
    }

    public PaymentService getPayment() {
        return payment;
    }

    public void setPayment(PaymentService payment) {
        this.payment = payment;
    }

    public List<FBillServices> getAllServices() {
        return allServices;
    }

    public void setAllServices(List<FBillServices> allServices) {
        this.allServices = allServices;
    }

    public String getAccName() {
        return accName;
    }

    public void setAccName(String accName) {
        this.accName = accName;
    }

    public String getAccNo() {
        return accNo;
    }

    public void setAccNo(String accNo) {
        this.accNo = accNo;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public Integer getBiller() {
        return biller;
    }

    public void setBiller(Integer biller) {
        this.biller = biller;
    }
}
